<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 摆动排序 -->
    <script>
      var wiggleMaxLength = function (nums) {
        if (nums.length < 2) return nums.length
        let down = 1,
          up = 1
        for (let i = 1; i < nums.length; i++) {
          if (nums[i] > nums[i - 1]) {
            up = down + 1
          } else if (nums[i] < nums[i - 1]) {
            down = up + 1
          }
        }
        return Math.max(down, up)
      }
      console.log(wiggleMaxLength([1, 7, 4, 9, 2, 5]))
    </script>
  </body>
</html>
